<template>
  <div class="allocate">
    <Module-title label="调拨板块">
      <G-select
        slot="right"
        v-model="queryParams.department_id"
        :options="deptList"
        @change="getList"
      />
    </Module-title>
    <div class="allocate-row">
      <G-select
        v-model="queryParams.type"
        :options="typeList"
        width="75px"
        height="33px"
        class-name="allocate-item"
        @change="changeType"
      />
      <G-date-picker
        v-model="queryParams.num"
        :date-type="
          queryParams.type == 1 ? 'year' : queryParams.type == 2 ? 'month' : 'date'
        "
        width="75px"
        height="33px"
        class-name="allocate-item"
        @change="getList"
      />
      <div class="allocate-search">
        <el-input
          v-model="queryParams.name"
          prefix-icon="el-icon-search"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="getList"
          @blur="getList"
          @clear="getList"
        />
      </div>
    </div>
    <G-table
      id="allocate"
      height="220px"
      :speed="50"
      :columns="columns"
      :data="dataList"
    />
  </div>
</template>
<script>
import { getTransferRecord } from "@/utils/srceen";
export default {
  name: "allocate-srceen",
  props: {
    // 科室列表
    deptList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      queryParams: {
        department_id: "",
        type: "1",
        num: "",
        name: "",
      },
      typeList: [
        { name: "年", id: "1" },
        { name: "月", id: "2" },
        { name: "日", id: "3" },
      ],
      columns: [
        { label: "设备名称", prop: "name", align: "left" },
        { label: "品牌", prop: "pinpai" },
        { label: "序列号", prop: "serial" },
        { label: "调入科室", prop: "department" },
        { label: "时间", prop: "create_time" },
      ],
      dataList: [],
    };
  },
  watch: {
    deptList: {
      handler(val) {
        if (val.length) {
          this.queryParams.department_id = val[0].id;
          this.changeType();
        }
      },
      immediate: true,
    },
  },
  methods: {
    // 切换时间类型
    changeType() {
      this.queryParams.num = this.parseTime(Date.now(), "{y}-{m}-{d}");
      this.getList();
    },
    // 获取列表
    getList() {
      let params = Object.assign({}, this.queryParams);
      if (params.type == "1") {
        params.num = this.parseTime(params.num, "{y}");
      } else if (params.type == "2") {
        params.num = this.parseTime(params.num, "{y}-{m}");
      } else if (params.type == "3") {
        params.num = this.parseTime(params.num, "{y}-{m}-{d}");
      }
      getTransferRecord(params).then((res) => {
        if (res && res.code == 1) {
          this.dataList = res.data || [];
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.allocate {
  width: 100%;
  height: 338px;
  background-color: rgba(0, 37, 111, 0.4);
  margin-top: 22px;
  &-row {
    display: flex;
    align-items: center;
    margin: 13px 10px 16px;
    .allocate-item {
      font-family: PingFang SC;
      font-weight: bold;
      font-size: 13px;
      display: flex;
      align-items: center;
      background: url("~@/assets/select-bg2.png") no-repeat;
      background-size: 100% 100%;
      &:hover {
        cursor: pointer;
        background: url("~@/assets/select-bg2-hover.png") no-repeat;
        background-size: 100% 100%;
      }
      &:first-child {
        margin-right: 10px;
      }
    }
    .allocate-search {
      flex: 1;
      margin-left: 50px;
      height: 38px;
    }

    ::v-deep .el-input__inner {
      background: linear-gradient(
        270deg,
        rgba(1, 135, 191, 0.3) 0%,
        rgba(1, 135, 191, 0) 100%
      ) !important;
      border: none !important;
      color: #fff !important;
      &::placeholder {
        color: #fff;
      }
    }
  }
}
</style>
